//
//  NNNavigationController.swift
//  CommonTool
//
//  Created by tenroadshow on 12.1.22.
//

import UIKit

class NNNavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        if #available(iOS 13.0, *) {
            let appearance = UINavigationBarAppearance()
            // 设置导航栏背景色
            appearance.backgroundColor = .white
            // 去除导航栏阴影（如果不设置clear，导航栏底下会有一条阴影线）
//            appearance.shadowColor = UIColor.clear
            
            appearance.setBackIndicatorImage(UIImage(named: "123"), transitionMaskImage: UIImage(named: "123"))
            
            // 字体颜色
            appearance.titleTextAttributes = [ NSAttributedString.Key.foregroundColor: UIColor.black]
            navigationBar.standardAppearance = appearance
            navigationBar.scrollEdgeAppearance = appearance
        }else {
            let appearance = UINavigationBar.appearance()
            appearance.setBackgroundImage(UIImage(color: .red,
                                                  size: CGSize(width: CC.screenW, height: CC.statusWithNavBarHeight)),
                                          for: .default)
            appearance.shadowImage = UIImage()
        }
        navigationBar.isTranslucent = false
    }
    
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if viewControllers.count > 0  {
            viewController.hidesBottomBarWhenPushed = true
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "tn_navigationbar_back")?.withRenderingMode(.alwaysOriginal),
                                                                              style: .done,
                                                                              target: self,
                                                                              action: #selector(popBackAction))
            
        }
        super.pushViewController(viewController, animated: animated)
    }
    
    @objc func popBackAction() {
        popViewController(animated: true)
    }

}
